// 预检中间件
const cors = async (ctx, next) => {

    console.log('预检中间件执行————————');
    await next()
    ctx.set("Access-Control-Allow-Origin", "http://127.0.0.1:3001/");
  
    ctx.set("Access-Control-Allow-Methods", "OPTIONS,POST,GET,HEAD,DELETE,PUT");
    
    ctx.set("Access-Control-Allow-Headers", "x-requested-with, accept, origin, content-type, token");
    
    ctx.set("Content-Type", "application/json;charset=utf-8");
    
    ctx.set("Access-Control-Max-Age", 300);
  
    ctx.set("Access-Control-Allow-Credentials", true);
  
    ctx.set("Access-Control-Expose-Headers", "myData");
    if (ctx.request.method === "OPTIONS") {
      ctx.response.status = 204
    }
  }
  // 这个是 egg 中间件包的函数，最后将这个函数导出即可
  module.exports = (options,app) => {
    return cors;
  }
